"use strict";
cc._RF.push(module, 'c430drFtedHy46fG0EXb1KJ', 'storage');
// Script/SdkTools/storage.ts

"use strict";
/**
 * 数据存储类
 * 单例模式
 */
Object.defineProperty(exports, "__esModule", { value: true });
var PlayData_1 = require("./PlayData");
var gameShareAdsVideo_1 = require("./gameShareAdsVideo");
var storage = /** @class */ (function () {
    function storage() {
        this.eneryTime = 0; //记录倒计时
        this.nowEnery = 0; //当前体力值
        this.addgoldcishu = 5;
        this.isfirstlogin = true;
        this.jilvchenghao = -1;
        this.jilvherolv = -1;
    }
    Object.defineProperty(storage, "Instance", {
        get: function () {
            if (null == this._instance) {
                this._instance = new storage();
            }
            return this._instance;
        },
        enumerable: false,
        configurable: true
    });
    storage.prototype.setCheckPoint = function (t) {
        cc.sys.localStorage.setItem("checkpoint", t);
    };
    storage.prototype.getCheckPoint = function () {
        var t = cc.sys.localStorage.getItem("checkpoint");
        return t = t || 1, Number(t);
    };
    //找不同 
    storage.prototype.setCheckPoint_diff = function (t) {
        var info = JSON.stringify(t);
        cc.sys.localStorage.setItem('checkpoint_diff', info);
        //cc.sys.localStorage.setItem("checkpoint_diff", t)
    };
    storage.prototype.getCheckPoint_diff = function () {
        var t = cc.sys.localStorage.getItem('checkpoint_diff');
        if (t === undefined || t === null || t === 'NaN' || t === '') {
            t = [[0], [0], [0], [0], [0]]; //字，图，找茬 0开启，1通过 -1或者无为未通过
        }
        else {
            t = JSON.parse(t);
        }
        return t;
        // var t = cc.sys.localStorage.getItem("checkpoint_diff");
        // return t = t || 1 ,Number(t)
    };
    //记录高分 或者关卡总是 用于排行
    storage.prototype.setHightScore = function (t) {
        cc.sys.localStorage.setItem("hightscore", t);
        gameShareAdsVideo_1.default.Instance.upWxHighScore(t, function () { });
    };
    storage.prototype.getHightScore = function () {
        var t = cc.sys.localStorage.getItem("hightscore");
        return t = t || 0, Number(t);
    };
    storage.prototype.setGold = function (t) {
        cc.sys.localStorage.setItem("gold", t);
    };
    storage.prototype.getGold = function () {
        var t = cc.sys.localStorage.getItem("gold");
        if (t === undefined || t === null || t === 'NaN' || t === '') {
            t = 0;
            this.setGold(0);
        }
        return Number(t);
    };
    storage.prototype.addGold = function (t) {
        var gold = this.getGold();
        gold += t;
        this.setGold(gold);
    };
    storage.prototype.setEnergy = function (t) {
        // 确保设置的体力值不超过10
        if (t > 10) {
            t = 10;
        }
        // 更新内存中的体力值
        this.nowEnery = t;
        // 持久化体力值到本地存储
        cc.sys.localStorage.setItem("tili", t.toString());
        // 可选：打印设置的体力，用于调试
        console.log('设置体力', t);
    };
    storage.prototype.getEnergy = function () {
        var t = cc.sys.localStorage.getItem("tili");
        if (t === undefined || t === null || t === 'NaN' || t === '') {
            t = 10;
            this.setEnergy(10);
        }
        this.nowEnery = Number(t);
        //console.log('获取的数据', this.nowEnery)
        return this.nowEnery;
    };
    storage.prototype.setTiShi = function (t) {
        cc.sys.localStorage.setItem("tishi", t);
    };
    storage.prototype.getTiShi = function () {
        var t = cc.sys.localStorage.getItem("tishi");
        if (t === undefined || t === null || t === 'NaN' || t === '') {
            t = 5;
            this.setTiShi(5);
        }
        return Number(t);
    };
    /**
     * 玩家信息
     */
    storage.prototype.setUserInfo = function () {
        console.log('存储userinfo');
        var info = JSON.stringify(PlayData_1.default.Instance.userInfo);
        //console.log('打印加密数据', info) 
        cc.sys.localStorage.setItem('userinfo', info);
    };
    storage.prototype.getUserInfo = function () {
        var _info = cc.sys.localStorage.getItem('userinfo') || null;
        if (_info) {
            var info = JSON.parse(_info);
            //console.log('打印解密数据', info) 
            PlayData_1.default.Instance.userInfo.hightScore = info.hightScore;
            PlayData_1.default.Instance.userInfo.icon = info.icon;
            PlayData_1.default.Instance.userInfo.openid = info.openid;
            PlayData_1.default.Instance.userInfo.name = info.name;
        }
        return PlayData_1.default.Instance.userInfo;
    };
    storage._instance = null;
    return storage;
}());
exports.default = storage;

cc._RF.pop();